package nl.rainbowsheep.reisorg.rest.service.model;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.List;
import javax.persistence.Temporal;
import javax.validation.constraints.NotNull;

/**
 * User is a SQL-reserved word, for that reason we decided to
 * rename User to BurritoUser. 
 */
@Entity
@Table(name = "burrito_users")
public class BurritoUser implements Serializable {

    protected BurritoUser() {}
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "burrito_user_id")
    private long id;

    @Column(name="registration_date")
    private Timestamp registrationDate; 
    
    @Column(name = "username")
    @NotNull
    private String username;

    @Column(name = "password")
    @NotNull
    private String password;

    @Column(name = "enabled")
    @NotNull
    private boolean enabled;

    @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    @JoinTable(name = "burrito_user_roles",
            joinColumns = {
                @JoinColumn(name = "burrito_user_fk")},
            inverseJoinColumns = {
                @JoinColumn(name = "burrito_role_fk")})    
    private List<BurritoRole> burritoUserRoles;

    @Column(name="delete_date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date deleteDate; 
    
    public long getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public List<BurritoRole> getBurritoUserRoles() {
        return burritoUserRoles;
    }

    public void setBurritoUserRoles(List<BurritoRole> burritoUserRoles) {
        this.burritoUserRoles = burritoUserRoles;
    }

    public Timestamp getRegistrationDate() {
        return registrationDate;
    }

    public void setRegistrationDate(Timestamp registrationDate) {
        this.registrationDate = registrationDate;
    }

    public Date getDeleteDate() {
        return deleteDate;
    }

    public void setDeleteDate(Date deleteDate) {
        this.deleteDate = deleteDate;
    }

    
}
